<template>
	<div class="task-cont">
		<ul>
			<li v-for="(item,index) in taskList">
				<p  @click="showOrHide($event)">{{item.taskName}} <span>{{item.complateNum}}/{{item.totleNum}}</span> <i class="ion ion-chevron-down"></i></p>
				<ul class="hideUl">
					<li v-for="obj in item.data" @click="urlGo(obj,item)" class="clearFix">
						<strong>{{obj.taskName}}<span v-if="obj.pointObject"> ({{obj.pointObject}})</span></strong> <b>{{obj.complateNum}} / {{obj.totleNum}}</b> <span>截止至：{{obj.endTime}}</span>
					</li>
				</ul>
			</li>
		</ul>
		<toast v-if="toastShow" :message="tipMessage"></toast>
		<confirm :message="confirmMessage" v-if="confirmShow" @close-dialog="closeConfirm"
                ></confirm>
	</div>
</template>
<script type="text/javascript">
	import SafeStyle from '../../assets/css/task.scss'

	import safeUrl from '../../assets/js/insterface'

	import getQuery from '../../assets/js/get_querys'

	import http from '../../assets/js/http_mixin'	

	import global from '../../assets/js/global'	

	export default{
		data(){ 
			return{
				tipMessage:'',
				taskList:[],
				empNo:'',
				urlName:''
			}
		},
		mixins:[getQuery,http],
		mounted(){
			document.title="任务列表";
			this.$el.parentElement.parentNode.style.background = '#F6F6F6';
			var query = this.getQuerys();
      		this.empNo = query.empNo;
			this.getData();
		},
		methods:{
			getData() {
				var vue = this;
				var param = {
					empNum: this.empNo
				}
				this.getInfo({
					url:safeUrl.taskList,
					param:param,
					success(data) {
						if(data.data.resultCode == "1"){
							vue.taskList = data.data.resultData
						}
						console.log(data.data.resultData);
						setTimeout(function(){
							document.querySelectorAll("i")[0].className = "ion ion-chevron-up";
						},10)
						
					}
				})
			},
			showOrHide(e) {
				var objs = document.querySelectorAll(".hideUl");
				var icons = document.querySelectorAll("i");
				for(let ele of objs){
					ele.style.display = "none";
				}
				for(let ico of icons){
					ico.className = "ion ion-chevron-down";
				}
				e.currentTarget.nextElementSibling.style.display = "block";
				e.currentTarget.childNodes[3].className = "ion ion-chevron-up";
			},
			urlGo(obj,item) {
				console.log("????")
				console.log(obj)
				var vue = this;
				if(obj.complateNum == 0 && obj.taskName == '参加安全会'){
					this.confirmShow = true;
					this.confirmMessage = '请确保安全会主持人/记录人已经把您添加到该次会议纪要的参加人员列表中';
					return
				}else if(global.taskSwitch(obj.taskId) == 'raDialog' && obj.complateNum == 0){
					this.confirmShow = true;
					this.confirmMessage = '您还有未被RA的任务，请尽快邀请你的老板给你做一个';
					return
					// this.$http.post(safeUrl.taskRalog,{empNo:this.empNo},{emulateJSON: true})
					// .then((response)=>{
					// 	if(response.data.type == "1"){
					// 		vue.toastShow = true;
				 //            vue.tipMessage = '您还有未被RA的任务，请尽快邀请你的老板给你做一个';
				 //            setTimeout(function(){
				 //              vue.toastShow = false;
				 //            },1500);
				 //            return false;
					// 	}else{
					// 		vue.urlName = global.taskSwitch(obj.taskId);
					// 		// console.log(global.taskSwitch(obj.taskId))
					// 		vue.$router.push({path:'/SafeMenu/' + vue.urlName,query:{empNo:vue.empNo,qid:obj.id}});
					// 	}
					// });
				}else{
					this.urlName = global.taskSwitch(obj.taskId);
					// console.log(global.taskSwitch(obj.taskId))
					console.log(item)
					if(item.taskName === '事故任务' || item.taskName === '其他任务'){
						this.$router.push({path:'/SafeMenu/' + this.urlName,query:{empNo:this.empNo,qid:obj.id,typeName:obj.taskName,addReq:true}});
					}else {
						this.$router.push({path:'/SafeMenu/' + this.urlName,query:{empNo:this.empNo,qid:obj.id,typeName:obj.taskName}});
					}
				}
				
			}
		}
	}

</script>